package com.andnnl.pool.retry;

import java.util.concurrent.DelayQueue;

/**
 * 延迟重试消息队列
 * Created by chenss on 2021/6/23.
 */
public class RetryMsgQueue<T> {
    private final DelayQueue<RetryMsg<T>> queue = new DelayQueue<>();

    public void addRetryTask(RetryMsg<T> retryMsg){
        queue.add(retryMsg);
    }

    public RetryMsg<T> taskRetryMsg(){
        try {
            return queue.take();
        } catch (InterruptedException e) {
//            e.printStackTrace();
        }
        return null;
    }

    public int getSize(){
        return queue.size();
    }
}
